<?php
class ActivityCommonDataVo extends SzAbstractMySqlVo
{

    private $userId;
    private $activityId;
    private $usePoint;
    private $totalPoint;
    private $rewardInfo;
    private $createTime;
    private $endTime;

    /**
     * Initialize ActivityCommonDataVo.
     *
     * @param $userId
     * @param $activityId
     * @param $usePoint
     * @param $totalPoint
     * @param $rewardInfo
     * @param $createTime
     * @param $endTime
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return ActivityCommonDataVo
     */
    public function __construct($userId, $activityId, $usePoint, $totalPoint, $rewardInfo, $createTime, $endTime, $isInsert = false) {
        $this->userId = $userId;
        $this->activityId = $activityId;
        $this->usePoint = $usePoint;
        $this->totalPoint = $totalPoint;
        $this->rewardInfo = json_decode($rewardInfo, true);
        $this->createTime = $createTime;
        $this->endTime = $endTime;

        $this->isInsert = $isInsert;
        $this->voClassName = 'ActivityCommonDataVo';
        $this->ormName = 'ActivityCommonData';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'activityId' => $this->getActivityId(),
            'usePoint' => $this->getUsePoint(),
            'totalPoint' => $this->getTotalPoint(),
            'rewardInfo' => ($needEncode) ? $this->getRewardInfo() : $this->getRawRewardInfo(),
            'createTime' => $this->getCreateTime(),
            'endTime' => $this->getEndTime(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'activityId' => $this->getActivityId(),
            'usePoint' => $this->getUsePoint(),
            'totalPoint' => $this->getTotalPoint(),
            'rewardInfo' => ($needEncode) ? $this->getRewardInfo() : $this->getRawRewardInfo(),
            'createTime' => $this->getCreateTime(),
            'endTime' => $this->getEndTime(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getActivityId(),
            $this->getUsePoint(),
            $this->getTotalPoint(),
            $this->getRewardInfo(),
            $this->getCreateTime(),
            $this->getEndTime(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getActivityId()
    {
        return $this->activityId;
    }

    public function setActivityId($val)
    {
        $this->saveColumnStatus(1, $this->activityId);
        $this->activityId = $val;
    }

    public function getUsePoint()
    {
        return $this->usePoint;
    }

    public function setUsePoint($val)
    {
        $this->saveColumnStatus(2, $this->usePoint);
        $this->usePoint = $val;
    }

    public function getTotalPoint()
    {
        return $this->totalPoint;
    }

    public function setTotalPoint($val)
    {
        $this->saveColumnStatus(3, $this->totalPoint);
        $this->totalPoint = $val;
    }

    public function getRewardInfo()
    {
        return json_encode($this->rewardInfo);
    }

    public function getRawRewardInfo()
    {
        return $this->rewardInfo;
    }

    public function setRewardInfo($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 25600) {
            SzLogger::get()->error('[ActivityCommonDataVo] The length of column rewardInfo exceed the limit, length / limit: ' . $encodedLength . ' / 25600');
            throw new SzException(10522, array('ActivityCommonDataVo', '25600', $encodedLength));
        } else if ($encodedLength > 23040) {
            SzLogger::get()->warn('[ActivityCommonDataVo] The length of column rewardInfo exceed the warning level, length / limit: ' . $encodedLength . ' / 25600');
        }
        $this->saveColumnStatus(4, $this->rewardInfo);
        $this->rewardInfo = $val;
    }

    public function getCreateTime()
    {
        return $this->createTime;
    }

    public function setCreateTime($val)
    {
        $this->saveColumnStatus(5, $this->createTime);
        $this->createTime = $val;
    }

    public function getEndTime()
    {
        return $this->endTime;
    }

    public function setEndTime($val)
    {
        $this->saveColumnStatus(6, $this->endTime);
        $this->endTime = $val;
    }

}